// import Home from '@/pages/Home'
// import Search from '@/pages/Search'
// import Login from '@/pages/Login'
// import Register from '@/pages/Register'
// import Detail from '@/pages/Detail'
// import AddCartSuccess from '@/pages/AddCartSuccess';
// import ShopCart from '@/pages/ShopCart';
// import Trade from '@/pages/Trade'
// import Pay from '@/pages/Pay'
// import PaySuccess from '@/pages/PaySuccess';
// import Center from '@/pages/Center';

// 二级路由
// import MyOrder from "@/pages/Center/MyOrder";
// import GroupOrder from "@/pages/Center/GroupOrder";
/*
当打包构建应用时，JS包会变得非常大，影响页面加载
如果我们能把不同路由对应的组件分割成不同的代码快，然后当路由被访问的时候菜价在对应组件，这样就更加高效了
*/

export default [
  {
    path: "/center",
    component: () => import("@/pages/Center"),
    meta: {
      showFooter: true,
    },
    name: "center",
    children: [
      {
        path: "myorder",
        component: () => import("@/pages/Center/MyOrder"),
      },
      {
        path: "grouporder",
        component: () => import("@/pages/Center/GroupOrder"),
      },
      {
        path: "/center",
        redirect: "/center/myorder",
      },
    ],
  },
  {
    path: "/paysuccess",
    component: () => import("@/pages/PaySuccess"),
    meta: {
      showFooter: true,
    },
    name: "paysuccess",
  },
  {
    path: "/pay",
    component: () => import("@/pages/Pay"),
    meta: {
      showFooter: true,
    },
    name: "pay",
    beforeEnter: (to, from, next) => {
      if (from.path == "/trade") {
        next();
      } else {
        next(false);
      }
    },
  },
  {
    path: "/trade",
    component: () => import("@/pages/Trade"),
    meta: {
      showFooter: true,
    },
    name: "trade",
    beforeEnter: (to, from, next) => {
      // 独享守卫
      // 进入前trade前触发
      if (from.path == "/shopcart") {
        next();
      } else {
        next(false);
      }
    },
  },
  {
    path: "/shopcart",
    component: () => import("@/pages/ShopCart"),
    meta: {
      showFooter: true,
    },
    name: "shopcart",
  },
  {
    path: "/addcartsuccess",
    component: () => import("@/pages/AddCartSuccess"),
    meta: {
      showFooter: true,
    },
    name: "addCartSuccess",
  },
  {
    path: "/detail/:skuid?",
    component: () => import("@/pages/Detail"),
    meta: {
      showFooter: true,
    },
    name: "detail",
  },
  {
    path: "/home",
    component: () => import("@/pages/Home"),
    meta: {
      showFooter: true,
    },
  },
  {
    path: "/search/:keyword?",
    component: () => import("@/pages/Search"),
    meta: {
      showFooter: true,
    },
    name: "search",
  },
  {
    path: "/login",
    component: () => import("@/pages/Login"),
    meta: {
      showFooter: false,
    },
    name: "login",
  },
  {
    path: "/register",
    component: () => import("@/pages/Register"),
    meta: {
      showFooter: false,
    },
  },
  //重定向，当访问的时候立马定到首页
  {
    path: "*",
    redirect: "/home",
    meta: {
      showFooter: true,
    },
  },
];
